package algorithm;

/**
 * 优惠券 打折问题  超过50件的使用最大数字进行代替
 */
public class Other1 {
    /**
     * 存放 打折的阶梯
     */
    private static int[] discount = {10, 20, 30, 40, 50, Integer.MAX_VALUE};

    /**
     * 超过50件每件 3元
     */
    private static int[] discountPrice = {20, 15, 10, 8, 5, 3};

    public static void main(String[] args) {
        Integer res = getPrice(11);
        System.out.println(res);
    }

    /**
     * @param count 买的数量
     * @return
     */
    private static Integer getPrice(int count) {
        int res = 0;
        // 10 20 30 40  11
        for (int i = 0; i < discount.length; i++) {
            int diff = Math.min(discount[i], count) - (i > 0 ? discount[i - 1] : 0);
            if (diff <= 0) {
                return res;
            }
            res += diff * discountPrice[i];
        }

        return res;
    }
}
